<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>将字符串中每个单词的首字母转换为大写</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.ucwords" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ucwords</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">ucwords</span> &mdash; <span class="dc-title">将字符串中每个单词的首字母转换为大写</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.ucwords-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ucwords</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$str</code></span>
   [, <span class="methodparam">
    <span class="type">string</span> <code class="parameter">$delimiters</code><span class="initializer"> = &quot; \t\r\n\f\v&quot;</span>
   </span>
  ] ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   将 <code class="parameter">str</code> 中每个单词的首字符（如果首字符是字母）转换为大写字母，并返回这个字符串。
  </p>
  <p class="para">
   这里单词的定义是紧跟在 <code class="parameter">delimiters</code> 参数（默认：空格符、制表符、换行符、回车符、水平线以及竖线）之后的子字符串。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ucwords-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">str</code></dt>

     <dd>

      <p class="para">
       输入字符串。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">delimiters</code></dt>

     <dd>

      <p class="para">
       可选的 <code class="parameter">delimiters</code>，包含了单词分割字符。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ucwords-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回转换后的字符串。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.ucwords-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.4.32, 5.5.16</td>
       <td>
       增加了 <code class="parameter">delimiters</code> 参数。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.ucwords-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-6003">
    <p><strong>Example #1 <span class="function"><strong>ucwords()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$foo&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'hello&nbsp;world!'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$foo&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ucwords</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Hello&nbsp;World!<br /><br /></span><span style="color: #0000BB">$bar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'HELLO&nbsp;WORLD!'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$bar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ucwords</span><span style="color: #007700">(</span><span style="color: #0000BB">$bar</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;HELLO&nbsp;WORLD!<br /></span><span style="color: #0000BB">$bar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ucwords</span><span style="color: #007700">(</span><span style="color: #0000BB">strtolower</span><span style="color: #007700">(</span><span style="color: #0000BB">$bar</span><span style="color: #007700">));&nbsp;</span><span style="color: #FF8000">//&nbsp;Hello&nbsp;World!<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
  
  <p class="para">
   <div class="example" id="example-6004">
    <p><strong>Example #2 <span class="function"><strong>ucwords()</strong></span> 自定义 delimiters 的例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$foo&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'hello|world!'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$bar&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ucwords</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Hello|world!<br /><br /></span><span style="color: #0000BB">$baz&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ucwords</span><span style="color: #007700">(</span><span style="color: #0000BB">$foo</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"|"</span><span style="color: #007700">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Hello|World!<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.ucwords-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">此函数可安全用于二进制对象。</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.ucwords-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="strtoupper.html" class="function" rel="rdfs-seeAlso">strtoupper()</a> - 将字符串转化为大写</span></li>
    <li class="member"><span class="function"><a href="strtolower.html" class="function" rel="rdfs-seeAlso">strtolower()</a> - 将字符串转化为小写</span></li>
    <li class="member"><span class="function"><a href="ucfirst.html" class="function" rel="rdfs-seeAlso">ucfirst()</a> - 将字符串的首字母转换为大写</span></li>
    <li class="member"><span class="function"><a href="mb_convert_case.html" class="function" rel="rdfs-seeAlso">mb_convert_case()</a> - 对字符串进行大小写转换</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>